<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <script>

    function handleData(a,b=true){
      let aver=0
      let sum=0
      console.log(typeof b);
      for(let i=0;i<a.length;i++){
          sum+=a[i]
      }
      aver=sum/a.length
      if(b){//if的小括号里的条件为真才执行后面的操作，所以不用让b===true,显得有点冗余，所以b为true会直接执行后面的条件体
        return sum
      } else{
        return aver
      }
    }
    let arr=[1,6,5,8,7]
     console.log(handleData(arr,false));




  </script>
</body>
</html>